package website.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import website.advice.BaseResponse;
import website.domain.*;
import website.service.ResService;

import java.util.List;

@Api("资源控制类")
@BaseResponse
@RestController
@RequestMapping("/api/resource")
public class ResController {

    @Autowired
    private ResService resService;

    @ApiOperation("查询分类")
    @GetMapping("/classify")
    public ResModel<List<Classify>> list(){
        return resService.getClassify();
    }

    @ApiOperation("查询标签")
    @GetMapping("/tag")
    public ResModel<List<Tag>> listTag(){
        return resService.listTag();
    }

    @ApiOperation("查询分类名称")
    @GetMapping("/classify/{id}")
    public ResModel getClassifyName(@PathVariable Integer id){
        return resService.getClassifyName(id);
    }

    @ApiOperation("分页查询分类名称")
    @GetMapping("/classify/{current}/{size}")
    public ResModel<IPage<Classify>> getByClassifyPage(@PathVariable Integer current,@PathVariable Integer size){
        return resService.getByClassifyPage(current,size);
    }

    @ApiOperation("删除分类名称")
    @DeleteMapping("/classify/{id}")
    public ResModel delClassify(@PathVariable Integer id){
        return resService.delClassify(id);
    }

    @ApiOperation("添加分类名称")
    @PostMapping(path = "/classify",produces = "application/json")
    public ResModel addClassify(@RequestBody Classify classify){
        return resService.addClassify(classify);
    }

    @ApiOperation("分页分类查询资源")
    @GetMapping("/{current}/{size}/{id}")
    public ResModel<IPage<Resource>> page(@PathVariable Integer current,@PathVariable Integer size,@PathVariable Integer id){
        return resService.getByPage(current,size,id);
    }

    @ApiOperation("查询资源详情")
    @GetMapping("/{id}")
    public ResModel<Resource> getResource(@PathVariable Integer id){
        return resService.getResource(id);
    }

    @ApiOperation("删除资源信息")
    @DeleteMapping("/{id}")
    public ResModel delRes(@PathVariable Integer id){
        return resService.delRes(id);
    }

    @ApiOperation("添加资源信息")
    @PostMapping(path = "",produces = "application/json")
    public ResModel addRes(@RequestBody Resource resource){
        return resService.addRes(resource);
    }

    @ApiOperation("更新资源浏览量")
    @GetMapping("/views/{id}")
    public ResModel addResView(@PathVariable Integer id){
        return resService.addResView(id);
    }

    @ApiOperation("查询热门资源")
    @GetMapping("/hot")
    public ResModel<List<Resource>> getHot(){
        return resService.getHot();
    }

    @ApiOperation("查询自己资源")
    @GetMapping("/user/{current}/{size}/{uid}")
    public ResModel<IPage<Resource>> getByUidResList(@PathVariable Integer current,@PathVariable Integer size,@PathVariable Integer uid){
        return resService.getByUidResList(current,size,uid);
    }
}
